<template>
    <mian-layout @refresh="resetForm('search_data')">
        <template v-slot:conTop>
            <el-form size="mini" :inline="true" :model='search' ref="search_data" class="demo-form-inline search-form">
                <el-form-item label="广告位名称" prop="adPlaceName">
					<el-input v-model="search.adPlaceName" placeholder="广告位名称"></el-input>
				</el-form-item>
                <el-form-item label="所属地标" prop="arLandmarkName">
					<el-input v-model="search.arLandmarkName" placeholder="所属地标"></el-input>
				</el-form-item>
                <el-form-item label="广告商" prop="merchantName">
					<el-input v-model="search.merchantName" placeholder="广告商"></el-input>
				</el-form-item>
                <el-form-item label="投放时间" prop="dataTime">
                        <el-date-picker v-model="dataTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm:ss" />
                    </el-form-item>
                <el-form-item>
					<el-button type="primary" plain  icon="el-icon-search" @click="doSearch">搜索</el-button>
                        <el-button icon="el-icon-refresh-right" @click="resetForm('search_data')">重置</el-button>
				</el-form-item>
            </el-form>   
        </template>

        <my-table :loading="loading" :lists="tableData" @selectionChange="tableSelect" @pageChange="handleChange" :sequence="true" :page='page'>
            <el-table-column property="adPlaceTitle" label="广告位名称"  align='center'></el-table-column>
            <el-table-column property="arLandmarkName" label="所属地标"  align='center'></el-table-column>
            <el-table-column property="adPlaceMerchantName" label="广告商"  align='center'></el-table-column>
            <el-table-column property="" label="保证金"  align='center'>--</el-table-column>
            <el-table-column property="adDays" label="投放周期"  align='center'>
                <template slot-scope="scope">
                    <span>{{scope.row.adDays}}</span>天
                </template>
            </el-table-column>
            <el-table-column property="creatorAddress" label="单次UV点击付费"  align='center'>
                <template slot-scope="scope">
                    {{scope.row.uvPrice?scope.row.uvPrice.decimalTwoString:'--'}}
                </template>
            </el-table-column>
            <el-table-column property="dayTotalPrice" label="日奖励限额"  align='center'>
                <template slot-scope="scope">
                    {{scope.row.dayTotalPrice?scope.row.dayTotalPrice.decimalTwoString:'--'}}
                </template>
            </el-table-column>
            <el-table-column property="startTime" label="投放奖励总金额"  align='center'>
                <template slot-scope="scope">
                    {{scope.row.allTotalPrice?scope.row.allTotalPrice.decimalTwoString:'--'}}
                </template>
            </el-table-column>
            <el-table-column property="adPlaceOwnerName" label="广告位持有人"  align='center'></el-table-column>
            <el-table-column property="createTime" label="投放时间"  align='center'></el-table-column>
      
            <el-table-column prop="operation" align='center' label="操作" :width="100">
                <template slot-scope="scope">
                    <el-button size="mini" icon="el-icon-search" @click="goLook(scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </my-table>
    </mian-layout>
</template>
<script>
import myTable from '@/components/public/myTable';
import goodsCategory from '@/components/public/goodsCategory.vue';
import {
  get_ad_release_list,
} from '@/api/collext'
import myDialog from '@/components/public/myDialog';
export default {
    components:{
      myTable,
      goodsCategory,
      myDialog
    },
    data(){
        return{
            search:{
                adPlaceName:'',
                arLandmarkName:'',
                merchantName:'',
                endTime:'',
                startTime:''
            },
            dataTime:'',
            page:{
                pageSize:10,
                pageIndex:1,
			    total:0,
            },
            loading:true,
            tableData:[],
            multipleSelectionIds:[],
            totalRow:{}
        }
    },
    created(){
        this.getList()
    },
    mounted(){
        
    },
    methods:{
        getList(callback){
            this.loading = true
            if(this.dataTime){
                this.search.startTime = this.dataTime[0]
                this.search.endTime = this.dataTime[1]
            }
            get_ad_release_list({
                limit: this.page.pageSize,
                page: this.page.pageIndex,
                ...this.search
            }).then(res=>{
                this.loading = false
                this.tableData = res.data
                this.page.total = res.total
                this.totalRow = res.totalRow
                callback && callback()
            })
        },
        doSearch(){
            this.page.pageIndex = 1;
            this.getList();
        },
        refreshData(){
            this.page.pageIndex = 1;
            this.getList();
        },
        tableSelect(data){
            console.log("GGGG:",data)
        },
        handleChange(index) {
            this.page.pageIndex = index;
            this.getList();
        },
        reSetData(){
            this.page.pageIndex = 1;
            this.getList();
        },
        async goodsUp(item){
            const res = await goodsUp({adPlaceJobRecordId:item.adPlaceJobRecordId})
            if(res.success){
                this.$message.success('上架成功')
                this.getList()
            }else{
                this.$message.error(res.message)
            }
        },
        async goodsDown(item){
            const res = await goodsDown({adPlaceJobRecordId:item.adPlaceJobRecordId})
            if(res.success){
                this.$message.success('下架成功')
                this.getList()
            }else{
                this.$message.error(res.message)
            }
        },

        del(item) {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let fromData = new FormData()
				fromData.append('adPlaceJobRecordId', item.adPlaceJobRecordId)
                const res = await del_goods(fromData)
                if(res.success){
                    this.$message.success('删除成功')
                    this.page.pageIndex = 1
                    this.getList()
                }else{
                   // this.$message.error('删除失败');
                }
            }).catch(() => {});
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dataTime = []
            for (const key in this.search) {
               this.search[key] = ''
            }
            this.search.sellStatus = '0'
            this.page.pageIndex = 1
            this.getList()
        },
        // goEdit(item,onlyLook){
        //     //sessionStorage.setItem('details',JSON.stringify(item))
        //     this.$store.commit('tagsView/SET_REGETDATA',this.getList)  // 设置需要刷新的方法，修改后返回需要刷新数据
        //     this.$router.push(`/goods/add?id=${item.adPlaceJobRecordId}&onlyLook=${onlyLook}`)
        // },
        // goAdd(){
        //     this.$store.commit('tagsView/SET_REGETDATA',this.getList)  // 设置需要刷新的方法，修改后返回需要刷新数据
        //     this.$router.push('/goods/add')
        // },
        goLook(item){
            this.$store.commit('tagsView/SET_REGETDATA',this.getList)  // 设置需要刷新的方法，修改后返回需要刷新数据
            this.$router.push(`/advertising/release/${item.adPlaceJobRecordId}`)
        }
    }
}
</script>

<style lang="scss" scoped>
    .myanfbtntabbox{
        position: relative;
        z-index: 10;
        .mybtn{
            position: absolute;
            z-index: 10;
            right: 0;
            top: 0;
        }
    }
    .tbimgbox{
        display: flex;
        align-items: center;
        justify-content: center;
        img{
            width: 50px!important;
            height: 50px!important;
            max-width: 200px;
        }
    }
</style>